package mianxiangduixiang.week3;

import java.util.Random;

public class ChoiceSort {
    public static void main(String[] args) {
        sort();
    }

    private static void sort() {
        Random random = new Random();
        int min, l, temp;
        int[] a = new int[10];
        for (int i = 0; i < 10; i++) {
            a[i] = random.nextInt(50);
            System.out.print(a[i] + " ");
        }

        for (int i = 0; i < 10; i++) {
            l = i;
            min = a[i];
            for (int j = i + 1; j < 10; j++) {
                if (min > a[j]) {
                    min = a[j];
                    l = j;
                }
            }
            temp = a[i];
            a[i] = a[l];
            a[l] = temp;
        }
        System.out.println();
        for (int i = 0; i < 10; i++) {
            System.out.print(a[i] + " ");
        }
    }
}
